package com.me.web;

import com.me.pojo.User;
import com.me.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/selectUserServlet")
public class SelectUserServlet extends HttpServlet {
    UserService userService = new UserService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1. 接收用户名
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        //2. 调用service查询User对象
        String user= userService.selectByUsername(username);
        //3. 响应标记
        if (user != null) {
            //用户名可用
            response.getWriter().write("true");
        } else {
            //用户名不可用
            response.getWriter().write("false");
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}